package com.yanfan.parking.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yanfan.system.util.DeptTypeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.parking.domain.IbmsParkingRecords;
import com.yanfan.parking.service.IIbmsParkingRecordsService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 车辆进出场记录Controller
 *
 * @author lzb
 * @date 2024-08-09
 */
@Api(tags = "车辆进出场记录")
@RestController
@RequestMapping("/parking/inOutRecord")
public class IbmsParkingRecordsController extends BaseController {
    @Autowired
    private IIbmsParkingRecordsService ibmsVehicleInOutRecordService;


    /**
     * 查询车辆进出场记录列表
     */
    @ApiOperation("车辆进出场记录分页列表")
    @PreAuthorize("@ss.hasPermi('parking:inOutRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(IbmsParkingRecords ibmsParkingRecords) {
        startPage();
        List<IbmsParkingRecords> list = ibmsVehicleInOutRecordService.selectIbmsParkingRecordsList(ibmsParkingRecords);
        return getDataTable(list);
    }

    /**
     * 导出车辆进出场记录列表
     */
    @ApiOperation("导出车辆进出场记录列表")
    @PreAuthorize("@ss.hasPermi('parking:inOutRecord:export')")
    @Log(title = "车辆进出场记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IbmsParkingRecords ibmsParkingRecords) {
        List<IbmsParkingRecords> list = ibmsVehicleInOutRecordService.selectIbmsParkingRecordsList(ibmsParkingRecords);
        ExcelUtil<IbmsParkingRecords> util = new ExcelUtil<IbmsParkingRecords>(IbmsParkingRecords.class);
        util.exportExcel(response, list, "车辆进出场记录数据");
    }

    /**
     * 获取车辆进出场记录详细信息
     */
    @ApiOperation("获取车辆进出场记录详细信息")
    @PreAuthorize("@ss.hasPermi('parking:inOutRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ibmsVehicleInOutRecordService.getById(id));
    }

    /**
     * 新增车辆进出场记录
     */
    @ApiOperation("新增车辆进出场记录")
    @PreAuthorize("@ss.hasPermi('parking:inOutRecord:add')")
    @Log(title = "车辆进出场记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IbmsParkingRecords ibmsParkingRecords) {

        return toAjax(ibmsVehicleInOutRecordService.save(ibmsParkingRecords));
    }

    /**
     * 修改车辆进出场记录
     */
    @ApiOperation("修改车辆进出场记录")
    @PreAuthorize("@ss.hasPermi('parking:inOutRecord:edit')")
    @Log(title = "车辆进出场记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IbmsParkingRecords ibmsParkingRecords) {
        return toAjax(ibmsVehicleInOutRecordService.updateById(ibmsParkingRecords));
    }

    /**
     * 删除车辆进出场记录
     */
    @ApiOperation("删除车辆进出场记录")
    @PreAuthorize("@ss.hasPermi('parking:inOutRecord:remove')")
    @Log(title = "车辆进出场记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ibmsVehicleInOutRecordService.removeBatchByIds(Arrays.asList(ids)));
    }
}
